<template>
  <!-- 查看详情 2018/3/7 11:44 zhangQ -->
  <div>

    <tablePage ref="subOrderTab" :staticData="subOrderData" :isStartLoad="false" :mode="1" :showSizer="true" :pageSizeOpts="pageSizeOpts">
      <template slot-scope="props">
        <Table :columns="subOrderColumn" border :data="props.data" @on-sort-change="props.sortChange"></Table>
      </template>
    </tablePage>
  </div>
</template>

<script>
  import {getRailwayEmptyOrderListByOrderNo} from '@api/backEnd/station'
  import tablePage from '@components/table/tablePage.vue'
  import moment from 'moment'

  export default {
    name: 'view-detail',
    data () {
      let pageSizeOpts = [10, 25, 50]
      let subOrderColumn = [
        {
          title: '车序',
          ellipsis: 'true',
          key: 'trainSort',
          width: 95
        },
        {
          title: '车号',
          ellipsis: 'true',
          key: 'trainNumber',
          width: 200
        },
        {
          title: '箱号1',
          ellipsis: 'true',
          width: 210,
          key: 'containerNo1'
        },
        {
          title: '箱号2',
          ellipsis: 'true',
          width: 210,
          key: 'containerNo2'
        },
        {
          title: '绑定时间',
          ellipsis: 'true',
          width: 210,
          key: 'bindTime',
          render: (h, params) => {
            let thisdata = params.row.bindTime
            thisdata = thisdata ? moment(thisdata).format('YYYY-MM-DD HH:mm') : ''
            return (<span>{thisdata}</span>)
          }
        }
      ]
      let subOrderData = []
      let datas = {
        subOrderColumn,
        subOrderData,
        pageSizeOpts
      }
      return datas
    },
    props: {
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      /**
       * TODO(获得子运单信息)
       * @auther zhangQ
       * @date 2018/3/16 15:40
       **/
      getSubOrderData () {
        if (!(this.currentMainOrder && this.currentMainOrder.order_no)) {
          return
        }
        let param = {
          orderNo: this.currentMainOrder.order_no
        }
        getRailwayEmptyOrderListByOrderNo(param).then(res => {
          if (res.data.isSuccess === 1) {
            this.subOrderData = res.data.data
          } else {
            Promise.reject(new Error(res.data.res))
          }
        }).catch((err) => {
          console.log('接口getOrderDetail:' + err)
        })
      }
    },
    mounted () {
      this.getSubOrderData()
    },
    components: {tablePage}
  }
</script>
